package com.thunbu.lib_common.widget

import android.view.View
import android.widget.TextView
import com.thunbu.lib_common.R
import com.thunbu.lib_common.base.ToolBarHolder

class CommonToolBar: ToolBarHolder() {

    override fun provideLayoutId(): Int = R.layout.toolbar_common


    /**
     *  <返回按钮点击事件>
     */
    fun setBackAction(action:()->Unit){
        with(findViewById<View>(R.id.toolBar_Back)){
            visibility = View.VISIBLE
            setOnClickListener {
                action.invoke()
            }
        }
    }


    /**
     *  <设置标题>
     */
    fun setTitle(str:String){
        findViewById<TextView>(R.id.toolBar_Title).text = str
    }


    /**
     *  <切换风格>
     *  @param isDark 是否是黑色主题
     */
//    fun changeStyle(isDark:Boolean){
//        if (isDark){
//            findViewById<ImageView>(R.id.toolBar_Back).setImageResource(R.drawable.top_back_black)
//            (rootView as ViewGroup).forEach {
//                if (it is TextView){
//                    it.setTextColor(C)
//                }
//            }
//        }else{
//            findViewById<ImageView>(R.id.toolBar_Back).setImageResource(R.drawable.top_back_white)
//            (rootView as ViewGroup).forEach {
//                if (it is TextView){
//                    it.setTextColor(Color.WHITE)
//                }
//            }
//        }
//    }


    /**
     *  <设置右副标题>
     */
    fun setSubTitleRight(str:String, onClick: (View.() -> Any?)? = null){
        with(findViewById<TextView>(R.id.toolbar_SubtitleRight)){
            visibility = View.VISIBLE
            text = str
            if (onClick != null){
                setOnClickListener {
                    onClick.invoke(it)
                }
            }
        }
    }


    /**
     *  <设置左副标题>
     */
    fun setSubTitleLeft(str:String, onClick: (View.() -> Unit?)? = null){
        with(findViewById<TextView>(R.id.toolbar_SubtitleLeft)){
            visibility = View.VISIBLE
            text = str
            if (onClick != null){
                setOnClickListener {
                    onClick.invoke(it)
                }
            }
        }
    }
}